package com.top4create.model;

import com.top4create.model.BaseObject;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableComponent;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import javax.xml.bind.annotation.XmlRootElement;

import java.io.Serializable;

@Entity
@Table(name="favourate_buy",catalog="top4create_test")
@Searchable
@XmlRootElement
public class FavourateBuy extends BaseObject implements Serializable {
    private Long id;
    private BuyInfo buyInfo;
    private Long userId;

    @Id @GeneratedValue(strategy=IDENTITY) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="buy_id")
    public BuyInfo getBuyInfo() {
        return this.buyInfo;
    }
    
    public void setBuyInfo(BuyInfo buyInfo) {
        this.buyInfo = buyInfo;
    }
    
    @Column(name="user_id")
    @SearchableProperty
    public Long getUserId() {
        return this.userId;
    }
    
    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        FavourateBuy pojo = (FavourateBuy) o;

        if (buyInfo != null ? !buyInfo.equals(pojo.buyInfo) : pojo.buyInfo != null) return false;
        if (userId != null ? !userId.equals(pojo.userId) : pojo.userId != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (buyInfo != null ? buyInfo.hashCode() : 0);
        result = 31 * result + (userId != null ? userId.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("buyInfo").append("='").append(getBuyInfo()).append("', ");
        sb.append("userId").append("='").append(getUserId()).append("'");
        sb.append("]");
      
        return sb.toString();
    }

}
